﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManageSystem
{
    public partial class FormAddBook: Form
    {
        public FormAddBook()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //如果文本框内容有空 返回
            if (this.txtBookAuthor.Text.Trim() == "" ||
                txtBookId.Text.Trim() == "" || txtBookIntroduction.Text.Trim() == "" ||
                txtBookName.Text.Trim() == "" || txtBookQuantity.Text.Trim() == "" || txtBookPrice.Text.Trim() == ""
                || txtBookType.Text.Trim() == "")
            {
                MessageBox.Show("有空项", "提示", MessageBoxButtons.OK);
                return;
            }
            //添加图书
            Dao dao = new Dao();
            dao.Concnect();
            string sql = $"insert into T_Book values('{Convert.ToInt32(txtBookId.Text.Trim())}'," +
                $" '{txtBookName.Text}','{txtBookAuthor.Text}','{txtBookPublisher.Text}','{dateTimePicker1.Value}'," +
                $"'{txtBookType.Text}','{float.Parse(txtBookPrice.Text)}','{int.Parse(txtBookQuantity.Text)}'," +
                $"'{txtBookIntroduction.Text}','0')";
            if (dao.Execute(sql) > 0)
            {
                dao.DaoClose();
                MessageBox.Show("添加成功", "消息", MessageBoxButtons.OK);
                this.Close();
            }
            else
            {
                dao.DaoClose();
                MessageBox.Show("添加失败", "消息", MessageBoxButtons.OK);
            }
        }
    }
}
